<admintpl file="header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:U('NewsColumnEntrance/index',array($id_type=>$id_val))}">入口列表</a></li>
        <!-- <li><a href="#" onclick="addEntrance('{$column_id}');">添加栏目</a></li> -->
        <li class="active"><a href="{:U('NewsColumnEntrance/addEntrance',array($id_type=>$id_val))}" >添加入口</a></li>
        <li><a href="{:U('NewsColumnEntrance/entranceManageList',array($id_type=>$id_val))}" >入口管理</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form" id="myform" action="{:U('NewsColumnEntrance/addColumnEntrance')}"
			  enctype="multipart/form-data">
         <div class="control-group">
            <label class="span1 control-label" style="width: 90px;"><span style="color:red;">*</span>入口标题</label>
            <div class="span3">
            	<input type="text" name="title" value="{$info_data.title}" id="title">
            </div>
        </div>

		<div class="control-group">
			<label class="span1 control-label" style="width: 90px;">副标题</label>
			<div class="span3">
				<input type="text" name="subtitle" value="{$info_data.subtitle}" id="subtitle">
			</div>
		</div>
		<div class="control-group">
					<label class="span1 control-label" style="width: 90px;"><span style="color:red;">*</span>封面图片：</label>
					<div class="span4 wrapper">
						<div id="uploader-image">
							<div id="fileList" class="uploader-list">
								<div id="imageDiv" class="file-item thumbnail" style="width:150px;height: 150px;">
									<?php
										if(!empty($info_data['cover_image'])){
									?>
											<img id="imagePreview" src="{$info_data.cover_image}" style="width:150px;height: 140px;">
											<?php
										}else{
										?>
											<img id="imagePreview" src="__PUBLIC__/images/furley_bg.png" style="width:150px;height: 140px;">
											<?php
										}
										?>
									<div id="picker" class="info">选择图片&nbsp;&nbsp;&nbsp;&nbsp;</div>
									<input style="display:none;" type="file" id="imageFile" name="imageFile" >
								</div>
							</div>
						</div>
					</div><div style="color:red;float:left;margin-top:140px">*列表缩略  尺寸：270*186  格式：JPG/PNG</div>
				</div>
				
		<div class="control-group">
			<label class="span1 control-label" style="width: 90px;">快捷入口类型</label>
			<div class="span3">
				<select name="link_type">
					<option <?php if($info_data['link_type'] == 1){echo 'selected = "selected"';}?> value="1">新闻</option>
					<option <?php if($info_data['link_type'] == 2){echo 'selected = "selected"';}?> value="2">直播</option>
					<option <?php if($info_data['link_type'] == 3){echo 'selected = "selected"';}?> value="3">其他</option>
				</select>
			</div>
		</div>
		
        <div class="control-group">
			<label class="span1 control-label" style="width: 90px;"><span style="color:red;">*</span>url</label>
			<div class="span3">
				<input type="text" name="link_url" value="{$info_data.link_url}" id="link_url">
			</div>
		</div>
		<input type="hidden" name="image_url" id=""image_url"" value="{$info_data.cover_image}"">
		<input type="hidden" name="{$id_type}" id="{$id_type}" value="{$id_val}">
		<input type="hidden" name="entrance_id" id="entrance_id" value="<?php echo $info_data['entrance_id'];?>">
        <div class="form-actions" style="padding-left:260px;">
        	<button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            &nbsp;&nbsp;<a class="btn" href="{:U('NewsColumnEntrance/index',array($id_type=>$id_val))}">{:L('BACK')}</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
$(function(){
	var img = $('#imagePreview')[0].src;
	if(img){
		
	}
})
// ajax 提交表单
/*$(document).ready(function(){
    $("#ajaxform").click(function(){    // 提交按钮触发事件
        var tourl = $("#myform").attr("action");    // 获取 表单的 提交地址
        var title = $("#title").val();
		var subtitle  = $("#subtitle").val();
		var $("#select_id").find("option:selected").text();
		var column_id = $("#column_id").val();

        $.post("{:U('NewsColumnEntrance/addColumnEntrance')}",{name:name,weight:weight,column_id:column_id},function(result){
        	if(result == '1'){
        		var msg = '添加成功';
        	}else{
        		var msg = '添加失败';
        	}
        	
    		parent.layer.msg(msg,{time:2000},1,function(a){
        		
    		});
    		setTimeout(function(){
    			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    			parent.layer.close(index);
    		}, 1000);
          });
    });
    $("#ajaxback").click(function(){
    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.layer.close(index);
    });
});*/

function html5Reader(file, previewId){
	var file = file.files[0];
	var reader = new FileReader();
	reader.readAsDataURL(file);
	reader.onload = function(e){
		$('#'+previewId).attr('src', this.result);
	}
}
function image_change(fileId, previewId) {
	var pic = document.getElementById(previewId),
			file = document.getElementById(fileId);

	var ext = file.value.substring(file.value.lastIndexOf(".")+1).toLowerCase();

	// gif在IE浏览器暂时无法显示
	if(ext != 'png' && ext != 'jpg' && ext != 'jpeg'){
		alert("图片的格式必须为png或者jpg或者jpeg格式！");
		return;
	}
	var isIE = navigator.userAgent.match(/MSIE/)!= null,
			isIE6 = navigator.userAgent.match(/MSIE 6.0/)!= null;

	if(isIE) {
		file.select();
		var realLocalPath = document.selection.createRange().text;

		// IE6浏览器设置img的src为本地路径可以直接显示图片
		if (isIE6) {
			pic.src = realLocalPath;
		}else {
			// 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片，但是可以通过滤镜来实现
			pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\"" + realLocalPath + "\")";
			// 设置img的src为base64编码的透明图片 取消显示浏览器默认图片
			pic.src = '';
		}
	}else {
		html5Reader(file, previewId);
	}
}

$("#picker").click(function(){
	$("#imageFile").click();
});

$("#imageFile").change(function(){
	image_change('imageFile', 'imagePreview');
});
</script>
</body>
</html>